//
//  ZaiXianTianJiaXueShengCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/22.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZaiXianTianJiaXueShengCell.h"

@implementation ZaiXianTianJiaXueShengCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}

- (void)initSubView{
    UILabel * contLab = [UILabel new];
    CGFloat W = 1.0/8;
    for (int i = 0; i<8; i++){
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(W*i,0,W,44);
        label.numberOfLines = 0;
        label.textAlignment = 1;
        label.text = @"";
        label.tag = 30+i;
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [UIColor darkGrayColor];
        [self addSubview:label];
        if (i == 0) {
            contLab = label;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@0);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
        } else {
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
            if (i == 7) {
                _button = [UIButton buttonWithType:UIButtonTypeCustom];
                [_button setBackgroundImage:[UIImage imageNamed:@"add_teach"] forState:UIControlStateNormal];
                [_button setBackgroundImage:[UIImage imageNamed:@"fudao_close"] forState:UIControlStateSelected];
                label.userInteractionEnabled = YES;
                [label addSubview:_button];
                [_button mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.equalTo(label.mas_centerX);
                    make.centerY.equalTo(label.mas_centerY);
                    make.width.mas_equalTo(19);
                    make.height.mas_equalTo(19);
                }];
            }
        }
    }
    [self.button addTarget:self action:@selector(lookUp:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)lookUp:(UIButton *)sender{
    sender.selected = !sender.selected;
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"XueShengXiangQingShowNotice" object:nil userInfo:@{@"status":@"1",@"index":[NSString stringWithFormat:@"%d",self.index]}];
    if (sender.selected == YES) {
        self.block(_mainModel);
    }else{
        self.deleteBlock(_mainModel);
    }
    
}
- (void)reloadViewLayout{
    for (int i = 0; i<8; i++) {
        if (i == 7) {
            
        }else{
            UILabel *label = (UILabel *)[self viewWithTag:i+30];
            label.text = _dataArray[i];
        }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
